﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 方法重载
{
    class SumUtils
    {
        public int a { get; set; }
        public int b { get; set; }
        public double c { get; set; }
        public double d { get; set; }
        public string e { get; set; }
        public string f { get; set; }
        public int g { get; set; }

        public SumUtils(int a, int b)
        {
            this.a = a;
            this.b = b;
        }

        public SumUtils(double c, double d)
        {
            this.c = c;
            this.d = d;
        }

        public SumUtils(string e, string f)
        {
            this.e = e;
            this.f = f;
        }

        public SumUtils(int g)
        {
            this.g = g;
        }



        //计算两个整数相加、
        //    两个小数相加、 
        //    两个字符串相加、
        // 以及从 1 到指定整数的和的方法。
        public void sum(int a, int b) 
        {
            int sum = a + b;
            Console.WriteLine("俩整数相加和为：{0}",sum);
        }
        public void sum(double c, double d)
        {
            double sum = c + d;
            Console.WriteLine("俩小数相加和为：{0}", sum);
        }
        public void sum(string e, string f)
        {
            string sum = e + f;
            Console.WriteLine("俩字符串相加值为：{0}", sum);
        }
        public void sum(int g)
        {
            if (g<1)
            {
                Console.WriteLine("输入的数不能小于1.");
            }
            else
            {
                int sum = 0;
                for (int i = 1; i <= g; i++)
                {
                    sum = sum + i;
                }
                Console.WriteLine("1 到{0}的和的方法和为：{1}", g, sum);
            }
        }

    }
}
